/*
    SUSAN® - Sole of Unix Save ANything

   
   Copyright (C) 2011-2016 Skyatlas Co. LTD
   

   
*/

#ifndef BAREOS_SRC_DIRD_RUN_ON_INCOMING_CONNECT_INTERVAL_H_
#define BAREOS_SRC_DIRD_RUN_ON_INCOMING_CONNECT_INTERVAL_H_

#include <string>

class BareosDb;

namespace directordaemon {

class Scheduler;
class JobResource;

class RunOnIncomingConnectInterval {
 public:
  explicit RunOnIncomingConnectInterval(std::string client_name);

  ~RunOnIncomingConnectInterval() = default;
  RunOnIncomingConnectInterval(const RunOnIncomingConnectInterval&) = delete;
  RunOnIncomingConnectInterval(RunOnIncomingConnectInterval&&) = delete;
  RunOnIncomingConnectInterval operator=(const RunOnIncomingConnectInterval&) =
      delete;
  RunOnIncomingConnectInterval operator=(RunOnIncomingConnectInterval&&) =
      delete;

  void Run();

  // testing
  RunOnIncomingConnectInterval(std::string client_name,
                               Scheduler& scheduler,
                               BareosDb* db);

 private:
  time_t FindLastJobStart(JobResource* job);
  void RunJobIfIntervalExceeded(JobResource* job, time_t last_start_time);

  std::string client_name_;
  Scheduler& scheduler_;
  BareosDb* db_{nullptr};
};

}  // namespace directordaemon

#endif  // BAREOS_SRC_DIRD_RUN_ON_INCOMING_CONNECT_INTERVAL_H_
